<?php
class Role extends AppModel {
	var $name = 'Role';
	var $displayField = 'name';
	var $validate = array(
		'name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'display_name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'display' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	
	var $hasMany = array(
		'Permission' => array(
			'className' => 'Permission',
			'foreignKey' => 'permission_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
    
    function getDisplayRoles($convert=true)
    {
        $this->recursive = 0;
        $records = $this->find('all',array('conditions'=>array('Role.display'=>'yes','Role.status'=>'active')));
        if($convert)
        {
            $data = array();
            foreach($records as $record)
            {
                $data[$record['Role']['id']] = $record['Role']['display_name'];
            }
            return $data;
        }
        
        return $records;
    }
}
